package com.txhy.certificatechain.presenter.user;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.txhy.certificatechain.api.UrlAddress;
import com.txhy.certificatechain.presenter.base.BasePresenter;
import com.txhy.certificatechain.ui.view.account.OpenAccountView;
import com.txhy.certificatechain.utils.GsonUtil;

/*
 * -----------------------------------------------------------------
 * Copyright (C) 2018-2030, by your company, All rights reserved.
 * -----------------------------------------------------------------
 * 文    件: OpenAccountPresenter.java
 * 作    者: 侯建军
 * 版    权: 1.0.0
 * 描    述: 账户开通
 * 创建时间: 2018/9/20 10:35
 * 更新时间：2018/9/20 10:35
 * -----------------------------------------------------------------
 * 2018/9/20 10:35: 创建 OpenAccountPresenter.java (侯建军);
 * -----------------------------------------------------------------
 */
public class OpenAccountPresenter extends BasePresenter<OpenAccountView> {

    public void getMsg(String userId   ){
        OkGo.<String>post(UrlAddress.CGETINIT_URL)//
                .tag(this)//
                .params("userId", userId)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        if (GsonUtil.GsonGetStatus(response.body()) == 200) {
                            getView().getMsgSuccess(GsonUtil.GsonGetData(response.body()));
                        } else {
                            getView().getMsgFail(GsonUtil.GsonGetMsg(response.body()));
                        }
                    }
                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        getView().getMsgFail("请求失败请检查网络");
                    }
                });
    }




    public void openAccount(String userId  ,String userType,String money ){
        OkGo.<String>post(UrlAddress.OPENACCOUT_URL)//
                .tag(this)//
                .params("userId", userId)
                .params("userType", userType)
                .params("money", money)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        if (GsonUtil.GsonGetStatus(response.body()) == 200) {
                            getView().openSuccess(GsonUtil.GsonGetData(response.body()));
                        } else {
                            getView().openFail(GsonUtil.GsonGetMsg(response.body()));
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        getView().openFail("请求失败请检查网络");
                    }
                });
    }
}
